﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraGrid;
using RFS.BizLogic.Sys.impl;
using RFS.Domain.Sys;

namespace ProtoWinform
{
    public partial class frmUsers : Form
    {
        IConfigT _config;
        public frmUsers()
        {
            InitializeComponent();


            _config = AntiObject.Ins.Get<IConfigT>();
            _user=  _config.ConfigSys.Users;



            var dataGridView1 = this.gridControl1;

            dataGridView1.DataSource = _user;
            // dataGridView1.ReadOnly =  false ;

            // dataGridView1.AutoGenerateColumns = false;

        }


        private List<User> _user = new List<User>();

        private void bsave_Click(object sender, EventArgs e)
        {

            _config.ConfigSys.Users = _user;
            _config.SaveIt();

            DialogResult= DialogResult.OK;
            Close();
        }


        private GridControl dataGridView1
        {
            get => this.gridControl1;
        }

        void Refresh()
        {
            // dataGridView1.DataSource=null ; 
            dataGridView1.RefreshDataSource();  
        }
        private void button2_Click(object sender, EventArgs e)
        {
            var c = gridView1.GetSelectedObject<User>();
            // foreach (DataGridViewRow o in c)
            // {
                // var u= _user[o.Index];
                if (c!=null )
                _user.Remove(c);

            // }
            Refresh();
            _config.SaveIt();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            _user.Add( new User()
            {
                
            });
            
            Refresh();
            _config.SaveIt();

        }
    }
}
